/*
author: sailing
date: 2018/11/7
func: 症状记
**/

<template>
	<div class="srecord-page">
		<headback></headback>
		<div class="container">
			<mu-paper :z-depth="1" class="demo-list-wrap">
			
		</mu-paper></br>

		<mu-paper :z-depth="1" class="demo-list-wrap">
			<timeSet :rtime="rtime" :bntName= 'bntName'></timeSet>
		</mu-paper></br>

		<mu-paper style="display:block" :z-depth="1" class="demo-list-wrap">
			<mu-button style="text-align:left;margin-left:10px" @click="submit();" color="secondary">提交记录</mu-button>
		</mu-paper>
		</div>
	</div>
</template>

<script type="text/javascript">
	import headback from "./headback.vue"
	import timeSet from '../time.vue'
	import records from "../sdata.js";
	import tools from '../../server/tools.js';
	import Config from "../../server/Config.js";
	import fetch from "../../server/fetch.js";
	export default{
		data () {
			return {
				records: records,
				bntName: '开始',
				rtime: {
					start: '',
					end: ''
				}
			}
		},

		methods: {
			startTime () {
				let time = tools.getTime()
				const self = this
				
				if (self.bntName == '开始') {
					this.rtime.start = time
					self.bntName = '结束'
				}else {
					self.bntName = '开始'
				}
				
				function start () {
					setTimeout(function () {
						let time = tools.getTime()
						self.rtime.end = time
						if(self.bntName == '结束')
						start()
					}, 500)
				}

				start()
			},

			submit () {
				let postData = {
					title: "睡眠记录",
					user: Config.user,
					rtime: this.rtime
				}
				fetch.POST({
					path: "/sendmail",
					data: postData,
					callback: function() {
						console.log("sendmail");
					}
				});
			}
		},
		
		components:{
			headback,
			timeSet
		}
	}
</script>

<style lang='less'>
	.srecord-page{
		.container{
			margin-top:55px;
			text-align:left;
		}
	}
</style>
 